package br.edu.ufcg.dsc.actions.resource;

import java.util.List;
import java.util.Vector;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import org.yaz4j.Connection;
import org.yaz4j.PrefixQuery;
import org.yaz4j.ResultSet;

import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.ResourceType;
import br.edu.ufcg.dsc.domain.marc.parser.MARCXMLParser;
import br.edu.ufcg.dsc.services.Z3950Service;

import com.opensymphony.xwork2.ActionSupport;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/resource/resultZ3950.jsp")
@SuppressWarnings("serial")
public class SearchZ3950Action extends ActionSupport {

	private List<Resource> resources = new Vector<Resource>();

	private String attribute, query;

	private int page;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public String getAttribute() {
		return attribute;
	}

	public void setAttribute(String attribute) {
		this.attribute = attribute;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public List<Resource> getResults() {
		return resources;
	}

	public int getNext() {
		return page + 1;
	}
	
	public int getPrevious() {
		return page - 1;
	}
	
	@Override
	public String execute() throws Exception {
		
		Z3950Service.fill(resources, attribute, query, page);

		return SUCCESS;
	}
}
